package com.jp.knowledge.fragment;

import com.jp.knowledge.activity.JpApplicationWebActivity;
import com.jp.knowledge.adapter.SearchAttentionAdapter;
import com.jp.knowledge.model.IModel;
import com.jp.knowledge.my.base.RecycleVAdapter;

/**
 * Created by 528787067@qq.com on 2017/3/29.
 */

public class SearchAttentionFragment extends SearchDetailFragment {

	private SearchAttentionAdapter searchAttentionAdapter;

	public void setAction(String action) {
		this.action = action;
		if (searchAttentionAdapter != null) {
			searchAttentionAdapter.setAction(action);
		}
	}

	public void setId(String id) {
		this.id = id;
		if (searchAttentionAdapter != null) {
			searchAttentionAdapter.setId(id);
		}
	}

	public void setWebType(int type) {
		this.webType = type;
		if (searchAttentionAdapter != null) {
			searchAttentionAdapter.setType(type);
		}
	}

	private String groupId;

	public void setGroupId(String groupId) {
		this.groupId = groupId;
		if (searchAttentionAdapter != null) {
			searchAttentionAdapter.setGroupId(this.groupId);
		}
	}

	@Override
	protected void initData() {
		super.initData();
		searchAttentionAdapter = new SearchAttentionAdapter(mContext, list);
		searchAttentionAdapter.setId(id);
		searchAttentionAdapter.setAction(action);
		searchAttentionAdapter.setType(webType);
		searchAttentionAdapter.setGroupId(groupId);
		recyclerView.setAdapter(searchAttentionAdapter);
		searchAttentionAdapter.addItemClickListener(new RecycleVAdapter.OnItemClickListener() {
			@Override
			public void itemSelect(int position) {
				searchAttentionAdapter.updateTitleColor(position);
				switch (type) {
					case 3: // "公司";
						JpApplicationWebActivity.gotoWebActivity(getContext(),
								"details/companyDetails?id=" + list.get(position).getId() + "&type=" + list.get(position).getType());
						break;
					case 4: // "人物";
						JpApplicationWebActivity.gotoWebActivity(getContext(),
								"details/figureDetails?id=" + list.get(position).getId() + "&type=" + list.get(position).getType());
						break;
					case 8: // "产品";
						JpApplicationWebActivity.gotoWebActivity(getContext(),
								"details/productDetails?id=" + list.get(position).getId() + "&type=" + list.get(position).getType());
						break;
				}
			}
		});
	}

	@Override
	public void clearList() {
		super.clearList();
		if (list != null)
			searchAttentionAdapter.updateAdapter(list);
	}

	@Override
	public void done(IModel dataModel) {
		super.done(dataModel);
		searchAttentionAdapter.updateAdapter(list);
	}
}
